/* GUI CONVERTED from rcsomtac.i (converter v1.76) Thu Apr 11 05:26:19 2002 */
/* rcsomtac.i - ALTERNATE PACKAGE CODE FRAME                                  */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.3.1.4 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.5    LAST MODIFIED: 03/23/95    BY: GWM *J049*                 */
/* REVISION: 8.5    LAST MODIFIED: 03/25/96    BY: mnh *J0GD*                 */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98    BY: *K1Q4* Alfred Tan          */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00    BY: *N08T* Annasaheb Rahane    */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00    BY: *N0KP* Mark Brown          */
/* Revision: 1.3.1.3      BY: Dan Herman         DATE: 07/09/01  ECO: *P007*  */
/* $Revision: 1.3.1.4 $   BY: Jean Miller        DATE: 04/09/02  ECO: *P058*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

define variable old_pkg like pt_part extent 7 no-undo.
define variable last_field as character no-undo.
define variable prev_pkg_code like pkg_code_alt extent 7 no-undo.
define variable prev_charge_type like charge_type_alt extent 7 no-undo.
define variable err-fld as character no-undo.
define variable err-line as integer no-undo.
define variable clc-shipto like so_ship no-undo.
define variable clc-curr like so_curr no-undo.
define variable clc-pkg-line as integer no-undo.

assign
   clc-curr = so_curr
   clc-shipto = (if sod_dock <> "" then sod_dock else
                (if sod_ship <> "" then sod_ship else
                (if so_ship <> "" then so_ship else
                so_cust))).

on leave of pkg_code_alt do:
   clc-pkg-line = frame-index.
   run chk_part
       (input frame-index,
        input (input pkg_code_alt[frame-index]),
        input clc-shipto,
        input clc-curr,
        output err-line,
        input-output prev_pkg_code[clc-pkg-line]).
   if err-line > 0 then err-fld = "pkg_code".
end.

on leave of charge_type_alt do:
   clc-pkg-line = frame-index.
   run chk_charge
       (input frame-index,
        input (input charge_type_alt[frame-index]),
        output err-line,
        input-output prev_charge_type[clc-pkg-line]).
   if err-line > 0 then err-fld = "charge_type".
end.

/*  ALTERNATE PACKAGE CODE FRAME  */
i = 1.
assign
   ord_mult_alt = 0
   charge_type_alt = ""
   prev_pkg_code = ""
   prev_charge_type = ""
   pkg_code_alt = ""
   old_pkg = "".

if using_container_charges then do:
   display
      pkg_code_alt
      ord_mult_alt
      charge_type_alt
   with frame alt-clc.
   /* SET EXTERNAL LABELS          */
   setFrameLabels(frame alt-clc:handle).
end.
else do:

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame alt:handle).
   display pkg_code_alt with frame alt.
end.

LOAD:
for each act_mstr where act_nbr = sod_nbr
   and act_line = sod_line no-lock:

   old_pkg[i] = act_cont_part.

   if using_container_charges then
      assign
         prev_pkg_code[i] = act_cont_part
         prev_charge_type[i] = act_charge_type
         ord_mult_alt[i]    = act_ord_mult
         charge_type_alt[i] = act_charge_type
         pkg_code_alt[i] = act_cont_part
         i = i + 1.
   if i > 7 then leave LOAD.

end.

if using_container_charges then
   display
      c-alt-container
      c-std-pack
      c-charge-type
      pkg_code_alt
      ord_mult_alt
      charge_type_alt with frame alt-clc.
else
   display pkg_code_alt with frame alt.

UPDATE_PKGS:
do on endkey undo UPDATE_PKGS, leave UPDATE_PKGS
   on error undo UPDATE_PKGS, retry UPDATE_PKGS:
/*GUI*/ if global-beam-me-up then undo, leave.


   if using_container_charges then do:

      update
         pkg_code_alt[1] ord_mult_alt[1] charge_type_alt[1]
         pkg_code_alt[2] ord_mult_alt[2] charge_type_alt[2]
         pkg_code_alt[3] ord_mult_alt[3] charge_type_alt[3]
         pkg_code_alt[4] ord_mult_alt[4] charge_type_alt[4]
         pkg_code_alt[5] ord_mult_alt[5] charge_type_alt[5]
         pkg_code_alt[6] ord_mult_alt[6] charge_type_alt[6]
         pkg_code_alt[7] ord_mult_alt[7] charge_type_alt[7]
      with frame alt-clc editblk: editing:

         readkey.
         apply lastkey.

         if err-line > 0 then do:

            if err-fld = "pkg_code" then do:
               /*ITEM HAS NOT BEEN DEFINED AS A CONTAINER*/
               {pxmsg.i &MSGNUM=4447 &ERRORLEVEL=3
                  &MSGARG1=pkg_code_alt[err-line]}
            end.
            else do:
               /*NOT A VALID CHARGE TYPE*/
               {pxmsg.i &MSGNUM=4396 &ERRORLEVEL=3}
            end.

            if err-fld = "pkg_code" then do:
               err-fld = "".
               next-prompt pkg_code_alt[err-line] with frame alt-clc.
            end.
            else do:
               err-fld = "".
               next-prompt charge_type_alt[err-line] with frame alt-clc.
            end.

            err-line = 0.
            next editblk.

         end.

      end. /* EDITING */

   end. /* IF USING_CONTAINER_CHARGES */

   if not using_container_charges then
      set pkg_code_alt with frame alt.

   do i = 1 to 7:

      if pkg_code_alt[i] <> "" then do:

         if not can-find(pt_mstr where pt_part = pkg_code_alt[i])
         then do:
            /* PART NOT ON FILE */
            {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3 &MSGARG1=pkg_code_alt[i]}
            undo UPDATE_PKGS, retry UPDATE_PKGS.
         end.

         if using_container_charges then do:

            if not can-find(ptc_det where ptc_part = pkg_code_alt[i])
            then do:
               /*ITEM HAS NOT BEEN DEFINED AS A CONTAINER*/
               {pxmsg.i &MSGNUM=4447 &ERRORLEVEL=3 &MSGARG1=pkg_code_alt[i]}
               next-prompt pkg_code_alt[i] with frame alt-clc.
               undo UPDATE_PKGS, retry UPDATE_PKGS.
            end.

            if pkg_code_alt[i] <> old_pkg[i]
            then do:

               for first cclsc_mstr
               fields(cclsc_shipto cclsc_part cclsc_curr cclsc_charge_type)
               where cclsc_curr = so_curr
                 and cclsc_shipto = clc-shipto
                 and cclsc_part = input pkg_code_alt[i]
               no-lock:
                  charge_type_alt[i] = cclsc_charge_type.
               end.

               if not available cclsc_mstr then
               for first cclsc_mstr
               fields(cclsc_shipto cclsc_part cclsc_curr cclsc_charge_type)
               where cclsc_curr = so_curr
                 and cclsc_shipto = ""
                 and cclsc_part = input pkg_code_alt[i]
               no-lock:
                  charge_type_alt[i] = cclsc_charge_type.
               end.

               if not available cclsc_mstr then
               for first ptc_det
               fields(ptc_part ptc_charge ptc_charge_type)
               where ptc_part = input pkg_code_alt[i]
               no-lock:
                  if ptc_charge then
                     charge_type_alt[i] = ptc_charge_type.
                  else
                     charge_type_alt[i] = "".
               end.

            end. /* IF PKG_CODE_ALT  */

            if charge_type_alt[i] <> "" and
               not can-find(first cct_mstr where
                                  cct_charge_type = input charge_type_alt[i]
                              and cct_container_type)
            then do:
               /* NOT A VALID CHARGE TYPE*/
               {pxmsg.i &MSGNUM=4396 &ERRORLEVEL=3}
               next-prompt charge_type_alt[i] with frame alt-clc.
               undo UPDATE_PKGS, retry UPDATE_PKGS.
            end.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* IF USING_CONT_CHARGES */

         find act_mstr where act_nbr = sod_nbr
            and act_line = sod_line
            and act_cont_part = pkg_code_alt[i]
         exclusive-lock no-error.

         if not available act_mstr then do:
            create act_mstr.
            assign
               act_nbr = sod_nbr
               act_line = sod_line.
            if recid(act_mstr) = -1 then.
         end.

         assign
            act_ord_mult = ord_mult_alt[i]
            act_charge_type = charge_type_alt[i]
            act_cont_part = pkg_code_alt[i].

      end.  /* IF PKG_CODE_ALT <> */

      else do:

         find act_mstr where act_nbr = sod_nbr
            and act_line = sod_line
            and act_cont_part = old_pkg[i]
         exclusive-lock no-error.

         if available act_mstr then
            delete act_mstr.

      end.  /* ELSE DO */

   end. /* DO I = 1 TO 7 */

end. /* UPDATE_PKGS */

if using_container_charges then
   hide frame alt-clc no-pause.
else
   hide frame alt no-pause.

PROCEDURE chk_part:
   define input parameter ip_index as integer no-undo.
   define input parameter ip_part like pt_part no-undo.
   define input parameter ip_shipto like so_ship no-undo.
   define input parameter ip_curr like so_curr no-undo.
   define output parameter op_err_line as integer no-undo.
   define input-output parameter iop_prev_code like pt_part no-undo.

   if not using_container_charges then leave.

   op_err_line = 0.

   if iop_prev_code = ip_part then leave.

   else if ip_part = ""
   then do:
      display
         "" @ charge_type_alt[ip_index]
      with frame alt-clc.
      iop_prev_code = ip_part.
      leave.
   end.

   find first ptc_det where ptc_part = ip_part no-lock no-error.

   if not available ptc_det
   then do:
      op_err_line = ip_index.
      leave.
   end.

   iop_prev_code = ip_part.

   if ptc_charge = no
   then do:
      display
         "" @ charge_type_alt[ip_index]
      with frame alt-clc.
      leave.
   end.

   find first cclsc_mstr where
          cclsc_shipto = ip_shipto
      and cclsc_part = ip_part
      and cclsc_curr = ip_curr
   no-lock no-error.

   if not available cclsc_mstr then
   find first cclsc_mstr where
          cclsc_shipto = ""
      and cclsc_part = ip_part
      and cclsc_curr = ip_curr
   no-lock no-error.

   if available cclsc_mstr then
   display
      cclsc_charge_type @ charge_type_alt[ip_index]
   with frame alt-clc.

   else
   display
      ptc_charge_type @ charge_type_alt[ip_index]
   with frame alt-clc.

END PROCEDURE. /* PROCEDURE CHK_PART */

PROCEDURE chk_charge:
   define input parameter ip_index as integer no-undo.
   define input parameter ip_charge like cct_charge_type no-undo.
   define output parameter op_err_line as integer no-undo.
   define input-output parameter iop_prev_charge like cct_charge_type no-undo.

   if not using_container_charges then leave.

   op_err_line = 0.

   if iop_prev_charge = ip_charge then leave.

   else if ip_charge = "" then do:
      iop_prev_charge = ip_charge.
      leave.
   end.

   find first cct_mstr where cct_charge_type = ip_charge
                         and cct_container_type = yes
   no-lock no-error.

   if not available cct_mstr
   then do:
      op_err_line = ip_index.
      leave.
   end.

   iop_prev_charge = ip_charge.

END PROCEDURE. /* PROCEDURE CHK_CHARGE */
